
// import { config } from 'vue/types/umd';
import router from './router'
import store from './store'
const axios = require('axios');


  

  //request的拦截
  axios.interceptors.request.use(config => {
    if (store.state.token) {
      //每次请求都把token放到header里面
      config.headers.token = store.state.token;
    }
    return config
  })

  //每次的请求返回都要经过这里
  axios.interceptors.response.use(response=>{
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
 
     
    return response;
  }, function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    return Promise.reject(error);
  })

  //get请求

const getRequest=function(url,param){

    return new Promise((resolve,reject)=>{
      axios.get(url,param).then(res=>{
        return resolve(res.data);
      }).catch(err=>{
        reject(err);
      })
    })
      
  }

  export default{
    getRequest
  }


